home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / boot / netBoot.new / h / pr_util.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-19  |  3.4 KB  |  115 lines

  1.  
  2. /*    @(#)pr_util.h 1.1 86/09/27 SMI    */
  3.  
  4. /*
  5.  * Copyright (c) 1986 by Sun Microsystems, Inc.
  6.  */
  7.  
  8. /*
  9.  * Utilities for implementing pixdev operations.
  10.  */
  11.  
  12. /*
  13.  * Aids to handling overlapping source and destination.
  14.  * Given the from and to pr_pos's, rop_direction tells
  15.  * whether the rasterop is up or down and left or right,
  16.  * encoded as the ROP_UP and ROP_LEFT bits or their absence.
  17.  * The macros rop_is(up|down|left|right) can then be used.
  18.  */
  19. #define    ROP_UP        0x1
  20. #define    ROP_LEFT    0x2
  21.  
  22. #define    rop_direction(src, so, dst, do)    \
  23.         (   ( (((dst).x+(do).x) < ((src).x+(so).x)) << 1) | \
  24.               (((dst).y+(do).y) < ((src).y+(so).y))      )
  25. #define    rop_isleft(dir)        ((dir)&ROP_LEFT)
  26. #define    rop_isup(dir)        ((dir)&ROP_UP)
  27. #define    rop_isright(dir)    (((dir)&ROP_LEFT)==0)
  28. #define    rop_isdown(dir)        (((dir)&ROP_UP)==0)
  29.  
  30. /*
  31.  * Aids to producing fast loops, either unrolled or very tight:
  32.  *
  33.  * Cases8(n, op) produces the dense case part of a case statement
  34.  * for the cases [n+1..n+8), repeating ``op'' 1-8 times respectively.
  35.  *
  36.  * Rop_slowloop(n, op) produces a loop to do ``op'' n times, in little space.
  37.  * 
  38.  * Rop_fastloop(n, op) produces a loop to do ``op'' n times, in little time.
  39.  *
  40.  * Loop_d6(label, op) produces a dbra loop to do ``op'' the number of times
  41.  * in register d6 (second non-pointer register variable).
  42.  */
  43. #define cases8(n, op)                            \
  44.         case (n)+8: op; case (n)+7: op; case (n)+6: op;        \
  45.         case (n)+5: op; case (n)+4: op; case (n)+3: op;        \
  46.         case (n)+2: op; case (n)+1: op;                \
  47.  
  48. #define    rop_slowloop(n, op)                        \
  49.     { register int j = n; while (--j >= 0) { op; }}
  50.  
  51. #define    rop_fastloop(n, op)                        \
  52.     { register int j ;                        \
  53.       for (j = n; j > 15; j -= 16)                    \
  54.         { op; op; op; op; op; op; op; op;                \
  55.           op; op; op; op; op; op; op; op; }                \
  56.       switch (j) {                            \
  57.         cases8(8, op);                        \
  58.         cases8(0, op);                        \
  59.         case 0:    break;                        \
  60.       }                                \
  61.     }
  62.  
  63. #define loopd6(label, op)                        \
  64.     if (0) {                            \
  65.         asm("label:");                        \
  66.         op;                            \
  67.     };                                \
  68.     asm("dbra    d6,label");
  69.  
  70. /*
  71.  * Alloctype(datatype) allocates a datatype structure using calloc
  72.  * with the appropriate type cast.
  73.  */
  74. #define    alloctype(datatype)                        \
  75.         (datatype *)calloc(1, sizeof (datatype))
  76.  
  77. /*
  78.  * Pr_product is used when doing multiplications involving pixrects,
  79.  * and casts its arguments to that the compiler will use 16 by 16 multiplies.
  80.  */
  81. #ifdef sun
  82. #define pr_product(a, b)    ((short)(a) * (short)(b))
  83. #else
  84. #define pr_product(a, b)    ((a) * (b))
  85. #endif
  86.  
  87. /*
  88.  * Pr_area is the area of a rectangle.
  89.  */
  90. #define pr_area(size) pr_product((size).x, (size).y)
  91.  
  92. /*
  93.  * Pr_devdata is used to keep track of the valloced/mmapped virtual
  94.  * address of a device to prevent doing it more than necessary.
  95.  */
  96. struct pr_devdata {
  97.     int    fd;    /* fd that pixrect owns and is expected to close */
  98.     int    count;    /* reference count of this device */
  99.     short    *va;     /* valloced/mmapped virtual address managing */
  100.     int    bytes;    /* size of va for use when unvalloc unmap */
  101.     dev_t    rdev;    /* the device type, fd independent id of device */
  102.     struct    pr_devdata *next;    /* Link to other similar devices */
  103. };
  104.  
  105. #ifndef KERNEL
  106. struct    pixrect *pr_makefromfd();
  107. #endif !KERNEL
  108.  
  109. #ifdef    cplus
  110. struct    pixrect *pr_makefromfd(int fd, struct pr_size size, int depth,
  111.         struct pr_devdata **devdata, struct pr_devdata **curdd,
  112.         int mmapbytes, privdatabytes, mmapoffsetbytes);
  113. void    pr_unmakefromfd(int fd, struct pr_devdata **devdata);
  114. #endif    cplus
  115.